<!-- S search -->
<app-search-bar
  [submitLoading]="tableParams.loading"
  [searchOptions]="searchOptions"
  labelFlex="60px"
  (onSearch)="queryResetData($event)"
  (onReset)="queryResetData($event)"
>
</app-search-bar>
<!-- E search -->

<nz-card class="m-t-4">
  <div class="opera-wrap">
    <button
      nz-button
      nzType="primary"
      [nzLoading]="exportLoading"
      (click)="exportTable()"
    >导出</button>
  </div>

  <div class="pagination-wrap-position p-t-10">
    <nz-table
      #basicTable
      nzSize="small"
      nzShowSizeChanger
      nzShowQuickJumper
      nzBordered
      [nzScroll]="{ x: '1100px' }"
      [nzFrontPagination]="false"
      [nzLoadingDelay]="100"
      [nzLoading]="tableParams.loading"
      [nzData]="tableParams.tableData"
      [nzPageSizeOptions]="[5, 10, 20, 50, 100]"
      [nzTotal]="tableParams.total"
      [nzPageIndex]="tableParams.page"
      [nzPageSize]="tableParams.pageSize"
      [nzShowTotal]="totalTemplate"
      (nzPageIndexChange)="onPageIndexChange($event)"
      (nzPageSizeChange)="onPageSizeChange($event)"
    >
      <thead>
        <tr>
          <th nzAlign="center" nzWidth="220px" nzLeft>编码</th>
          <th nzAlign="center" nzWidth="120px">状态</th>
          <th nzAlign="center" nzWidth="220px">69码</th>
          <th nzAlign="center" nzWidth="180px">名称</th>
          <th nzAlign="center" nzWidth="150px">仓库</th>
          <th nzAlign="center" nzWidth="130px">品质</th>
          <th nzAlign="center" nzWidth="120px">库存数</th>
          <th nzAlign="center" nzWidth="120px">冻结数</th>
          <th nzAlign="center" nzWidth="150px" nzRight>操作</th>
        </tr>
      </thead>

      <tbody>
        <tr *ngFor="let data of basicTable.data; let index = index;">
          <!-- 编码 -->
          <td nzAlign="center" nzLeft>{{ data.goodsCode || '-' }}</td>
          <!-- 状态 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.state === 0 ? '#909399' : '#67C23A'}">
              {{ data.state === 0 ? '禁用' : '启用' }}
            </span>
          </td>
          <!-- 69码 -->
          <td nzAlign="center">{{ data.code || '-' }}</td>
          <!-- 名称 -->
          <td nzAlign="center">{{ data.name || '-' }}</td>
          <!-- 仓库 -->
          <td nzAlign="center">
            {{ filterText(warehouseOptions, data.whId) }}
          </td>
          <!-- 品质 -->
          <td nzAlign="center">
            <span>
              {{ data.quality === 0 ? '不良品' : (data.quality === 1 ? '良品' : '-') }}
            </span>
          </td>
          <!-- 库存数 -->
          <td nzAlign="center">{{ data.stockCount || '-' }}</td>
          <!-- 冻结数 -->
          <td nzAlign="center">{{ data.frozenStockCount || '-' }}</td>
          <!-- 操作 -->
          <td nzAlign="center" nzRight>
            <ng-container *ngIf="data.state === 1 && data.snState === 0; else elseTemplate">
              <a
                nz-button
                nzType="link"
                target="_blank"
                routerLink="/storage-center/storage-stock-sncode"
                [queryParams]="{goodsCode: data.goodsCode}"
              >SN记录</a>
            </ng-container>
            <ng-template #elseTemplate>
              -
            </ng-template>
          </td>
        </tr>

        <tr
          *ngIf="tableParams?.tableData?.length"
          style="background: #fafafa; font-weight: 600;">
          <td nzAlign="center" colSpan="6"><b>合计</b></td>
          <td nzAlign="center">{{ sumTotalData?.sumStock || '-' }}</td>
          <td nzAlign="center">{{ sumTotalData?.sumFrozenStock || '-' }}</td>
          <td nzAlign="center" nzRight>-</td>
        </tr>
      </tbody>
    </nz-table>

    <!-- 分页template -->
    <ng-template #totalTemplate let-total>共有 {{ total }} 条</ng-template>
  </div>
</nz-card>